$(function(){
apps.request({
	type: 'GET',
	timeout: 1000,
	url: urls.ctx + '/sys/user/menus',
	async: false,
	success: function(res){
		console.log(res);
		console.log('-------------------------------');
		if(res && res.code == 0) {
			if(res.user) {
				$('#img-touxiang').attr('src', res.user.picTouxiang);
				$('#h4-user-name').html(res.user.name);
				$('#profile-menu').append(res.user.email);
			}
			
			
			var h = '';
			var left = '';
			var router = new Router();
			if(res.list) {
				
				for(var i = 0; i < res.list.length; i++) {
					var item = res.list[i];
					if(item.href && item.href.length > 0) {
						var p = item.href.replace('#/', '')
						router.add(p, function() {
							$('#content').load(this.hash + '.html');
						}); 
						
					}
					
					var Class = '';
					if(item.isShow == 1 && item.parentId == '1') {
						var left1 = '';
						left1 += '	<a class="' + item.icon + '" href="">';
						left1 += '		<span class="menu-item">' + item.name + '</span>';
						left1 += '	</a>';
							
						var d = '';
						
						for(var j = 0; j < res.list.length; j++) {
							var r = res.list[j];
//		 							console.log('r.parentId=' + r.parentId);
//		 							console.log('item.id=' + item.id);
							if(r.parentId == item.id && r.isShow == 1) {
								d += '<li>';
								// d += '<a href="javascript:void(0);" onclick="jump(\'' + (r.href ? r.href : '404.html') +'\')">' + r.name + '</a>'
								d += '<a href="' + (r.href ? r.href : '404.html') +'">' + r.name + '</a>'
								d += '</li>';
							}
						}
						if(d.length > 0) {
							left1 = '';
							left1 += '	<a class="' + item.icon + '" href="javascript:void(0);">';
							left1 += '		<span class="menu-item">' + item.name + '</span>';
							left1 += '	</a>';
							
							left1 += '<ul  class="list-unstyled menu-item">';
							left1 += d;
							left1 += '</ul>';
							Class += 'dropdown';
							
							
							
						}
						left += '<li class="' + Class + '">' + left1 + '</li>';
					}
					
				}
				
				
			}
			router.setIndex('home');
			router.start();
						
			$('#side-menu').html(left);//dd class="layui-this"
			
		}
	}
	// error: function() {
		
	// }
});

//系统登出
$('#logout').unbind().bind('click', function() {
	apps.request({
		type: 'POST',
		url: urls.ctx + '/login/logout',
		success: function(res){
				console.log(res);
			if(res && res.code == 0) {
				// alert(res.msg);
				location.href = urls.login;
			} else {
				alert(res.msg);
			}
		},
		error: function() {
			
		}
	});
	return false;
});


});